﻿namespace Chain.IDAL
{
    using Chain.DBUtility;
    using Chain.Model;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.SqlClient;
    using System.Runtime.InteropServices;
    using System.Text;

    public class GoodsSlideshow
    {
        public int Add(Chain.Model.GoodsSlideshow model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("insert into GoodsSlideshow(");
            builder.Append("GoodsSlideshow_img,GoodsID)");
            builder.Append(" values (");
            builder.Append("@GoodsSlideshow_img,@GoodsID)");
            builder.Append(";select @@IDENTITY");
            SqlParameter[] cmdParms = new SqlParameter[] { 
                new SqlParameter("@GoodsSlideshow_img", SqlDbType.NVarChar, 200),
                new SqlParameter("@GoodsID", SqlDbType.Int, 4)
             };
            cmdParms[0].Value = model.GoodsSlideshow_img;
            cmdParms[1].Value = model.GoodsID;
            object single = DbHelperSQL.GetSingle(builder.ToString(), cmdParms);
            if (single == null)
            {
                return 0;
            }
            return Convert.ToInt32(single);
        }
        public DataSet GetList(string strWhere)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select * ");
            builder.Append(" FROM GoodsSlideshow where 1=1");
            if (strWhere.Trim() != "")
            {
                builder.Append(" and " + strWhere);
            }
            return DbHelperSQL.Query(builder.ToString());
        }
        public bool Delete(int GoodsSlideshowID)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("delete from GoodsSlideshow ");
            builder.Append(" where GoodsSlideshowID=@GoodsSlideshowID");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@GoodsSlideshowID", SqlDbType.Int, 4) };
            cmdParms[0].Value = GoodsSlideshowID;
            return (DbHelperSQL.ExecuteSql(builder.ToString(), cmdParms) > 0);
        }
        public Chain.Model.GoodsSlideshow GetModel(int GiftID)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select  top 1 * from GoodsSlideshow ");
            builder.Append(" where GoodsSlideshowID=@GoodsSlideshowID");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@GoodsSlideshowID", SqlDbType.Int, 4) };
            cmdParms[0].Value = GiftID;
            Chain.Model.GoodsSlideshow model = new Chain.Model.GoodsSlideshow();
            DataSet set = DbHelperSQL.Query(builder.ToString(), cmdParms);
            if (set.Tables[0].Rows.Count <= 0)
            {
                return null;
            }
            if ((set.Tables[0].Rows[0]["GoodsSlideshowID"] != null) && (set.Tables[0].Rows[0]["GoodsSlideshowID"].ToString() != ""))
            {
                model.GoodsSlideshowID = int.Parse(set.Tables[0].Rows[0]["GoodsSlideshowID"].ToString());
            }
            if ((set.Tables[0].Rows[0]["GoodsSlideshow_img"] != null) && (set.Tables[0].Rows[0]["GoodsSlideshow_img"].ToString() != ""))
            {
                model.GoodsSlideshow_img = set.Tables[0].Rows[0]["GoodsSlideshow_img"].ToString();
            }
            return model;
        }
    }
}

